package cn.bellychang.leetcode.question001;

/**
 * @author ChangLiang
 * @date 2020/9/6
 */
public class Solution {

    public int[] twoSum(int[] nums, int target) {
        for (int i = 0; i < nums.length; i++) {

            // 判断数组中除nums[i]之外 是否包含target-nums[i]的值 如果包含 就返回其indice 否则就返回-1
            int indiceY = getIndiceY(nums, i, target);
            if (indiceY != -1) {
                return new int[]{i, indiceY};
            }
        }
        return new int[]{};
    }

    private int getIndiceY(int[] nums, int indiceX, int target) {
        for (int i = 0; i < nums.length; i++) {
            if (i != indiceX && nums[i]+nums[indiceX]==target) {
                return i;
            }
        }
        return -1;
    }
}
